import random
def bubble_sort(li):
    for i in range(len(li)-1): #第i趟(从0开始)
        exchange = False
        for j in range(len(li)-i-1): #指针(从0开始)
            if li[j] > li[j+1]:
                li[j], li[j+1] = li[j+1], li[j]
                exchange = True
        if not exchange:
            return # 如果这一趟没有发生交换，说明数组已经排序好，直接返回
li = [random.randint(0,10000) for i in range(1000)]
print(li)
bubble_sort(li)
print(li)